<template>
  <!-- 方向盘 -->
  <div class="container-fluid" style="background:black">
    <div class="row" v-for="(row, rowindex) of this.dirs" :key=rowindex>
      <div class="col-4 p-0" v-for="(dir, index) of row" :key=index>
        <button type="button" :disabled=dir.disabled :class=btnclass() :value=index @click="ongodir($event)">{{dir.text}}</button>
      </div>
    </div>
  </div>
</template>

<script>

export default {
  data: function () {
    return {
      vdata: this.gdata.data,
      dirs: [{
        '西北': { text: '.', disabled: true },
        '北': { text: '.', disabled: true },
        '东北': { text: '.', disabled: true }
      },
      {
        '西': { text: '.', disabled: true },
        '中': { text: '.', disabled: true },
        '东': { text: '.', disabled: true }
      },
      {
        '西南': { text: '.', disabled: true },
        '南': { text: '.', disabled: true },
        '东南': { text: '.', disabled: true }
      }]
    }
  },
  components: {
  },
  mounted: function () {
  },
  computed: {
  },
  methods: {
    btnclass: function () {
      return (this.vdata.onpc ? 'btnwheeldirpc' : 'btnwheeldirph') + ' btn btn-outline-primary btn-sm btn-block p-0 m-0'
    },
    onkeyeventdir: function (dir) {
      var disabled = false
      for (var i = 0; i < this.dirs.length; i++) {
        var dirss = this.dirs[i]
        var dirsss = dirss[dir]
        if (typeof (dirsss) !== 'undefined') {
          if (dirsss.disabled === true) {
            disabled = true
            break
          }
        }
      }
      if (disabled) {
        this.jxtoast('这个方向没有出路')
        return
      }
      var reqinfo = this.wsreq('C2G_ROOM_GO')
      reqinfo.Dir = dir
      this.wssend(reqinfo)
    },
    ongodir: function (event) {
      var dir = event.srcElement.value
      if (event.srcElement.disabled) {
        return
      }
      var reqinfo = this.wsreq('C2G_ROOM_GO')
      reqinfo.Dir = dir
      this.wssend(reqinfo)
    },
    G2C: function (pid, rsp, success, result) {
      switch (pid) {
        case 'G2C_ROOM_INFO':
          var roominfo = rsp.RoomInfo
          for (let rowindex in this.dirs) {
            let row = this.dirs[rowindex]
            for (let dirindex in row) {
              let dir = row[dirindex]
              dir.text = '.'
              dir.disabled = true
            }
          }
          for (let rowindex in this.dirs) {
            let row = this.dirs[rowindex]
            for (let dirindex in row) {
              let dir = row[dirindex]
              for (let exit of roominfo.ListExit) {
                if (exit.Dir === dirindex) {
                  dir.text = this.conf.ConfigRoom[exit.RoomConfigId].Name
                  dir.disabled = false
                }
              }
            }
          }
          break
        default:
          // 这里是没有找到对应的值处理
          break
      }
    }
  }
}
</script>

<style scoped>
.btnwheeldirpc {
  white-space: normal;
  font-size: 20px;
}
.btnwheeldirph {
  white-space: normal;
  height: 36px;
  font-size: 12px;
}
</style>
